%{
/* fichier dans lequel est defini la macro constante TERMINAUX */
/*
bison -d while.y
flex while.l
g++ -o while while.tab.c lex.yy.c
*/
/* fichier dans lequel est defini la macro constante TERMINAUX */
#include <stdio.h>
#include <string>
#include "while.tab.h"
extern int ligne;
void yyerror(const char * msg);
int chr = 0;

int STATIQUES::nombre_variable=0;
int STATIQUES::L=0;
map<string,int> STATIQUES::fonctions;
string STATIQUES::derniere_variable="";

#define SAVE_TOKEN yylval.stringT = new std::string(yytext, yyleng)
#define TOKEN(t) (yylval.token = t)
#define printf(x) ; 

%}
%option noyywrap

opAffectation		":="
nombreEntier		[0-9]+
nombreFlottant		[0-9]+|[0-9]*\.[0-9]+
opPlus				\+
opMoins				\-
opDiv				\/
opMult				\*
identifiant			[a-zA-Z]+[a-zA-Z0-9]*
endOfLine			\n
opSuperieur			>
opInferieur			<
opSuperieurEgal		>=
opInferieurEgal		<=
opEgal				=
opDifferent			<>
True			"true"
False			"false"
Not				"!"
Et				"&&"
Ou				"||"
Int				"int"
Decimal			"decimal"
Array			"array"

Free 			"free"
New				"new"

Rt			    "return"

MotFonction		"function"
MotProcedure	"procedure"

If				"if"
Then			"then"
Else			"else"
While			"while"
Begin			"begin"
Do				"do"
End				"end"

Is				"is"

ParentheseOuvrante	"("
ParentheseFermante	")"
CrochetOuvrant		"["
CrochetFermant		"]"

Virgule				","
PointVirgule		";"
DeuxPoints			":"

%%

{opAffectation} {printf("\taffectation\n");return TOKEN(AFFECTATION);}

{opMoins} return TOKEN(MOINS);
{opPlus} return TOKEN(PLUS);
{opMult} return TOKEN(MUL);
{opDiv} return TOKEN(DIV);

{opSuperieur} return TOKEN(SUP);
{opInferieur} return TOKEN(INF);
{opSuperieurEgal} return TOKEN(INFEGAL);
{opInferieurEgal} return TOKEN(SUPEGAL);
{opEgal} return TOKEN(EGAL);
{opDifferent} return TOKEN(DIFF);

{nombreEntier} {SAVE_TOKEN; return N;}
{nombreFlottant} {SAVE_TOKEN; return D;}

{Rt} return TOKEN(RT);

{True} return TOKEN(TRUE);
{False} return TOKEN(FALSE);

{Not} return TOKEN(NOT);
{Et} return TOKEN(ET);
{Ou} return TOKEN(OU);

{Int} return TOKEN(INT);
{Decimal} return TOKEN(DECIMAL);
{Array} return TOKEN(ARRAY);

{PointVirgule} {printf("\t;\n");return TOKEN(POINTVIRGULE);}

{If} {printf("\tif\n");return TOKEN(IF);}
{Then} {printf("\tthen\n");return TOKEN(THEN);}
{Else} {printf("\telse\n");return TOKEN(ELSE);}	
{While} {printf("\twhile\n");return TOKEN(WHILE);}
{Begin} {printf("\tbegin\n");return TOKEN(BG);}
{Do} {printf("\tdo\n");return TOKEN(DO);}
{End} {printf("\tend\n");return TOKEN(END);}

{ParentheseOuvrante} {printf("\t(\n");return TOKEN(PARENTHESEOUVRANTE);}
{ParentheseFermante} {printf("\t)\n");return TOKEN(PARENTHESEFERMANTE);}

{CrochetOuvrant} {printf("\t[\n");return TOKEN(CROCHETOUVRANT);}
{CrochetFermant} {printf("\t]\n");return TOKEN(CROCHETFERMANT);}

{MotFonction} {printf("\tMotFonction\n");return TOKEN(MOTFONCTION);}
{MotProcedure} {printf("\tMotProcedure\n");return TOKEN(MOTPROCEDURE);}
{Is} {printf("\tIs\n");return TOKEN(IS);}

{Virgule} {printf("\t,\n");return TOKEN(VIRGULE);}
{DeuxPoints} {printf("\t:\n");return TOKEN(DEUXPOINTS);}

{Free} {printf("\tfree\n");return TOKEN(FREE);}
{New} {printf("\tnew\n");return TOKEN(NEW);}

{identifiant} {printf("X\n"); SAVE_TOKEN; return(X);}

[ \t] ; 
\n ; 
" "* ;

. return yytext[0];
%%
